Chapter 9
Voice-Activated Macros

As explained in Chapter 4, each command in Simon's vocabulary is actually a macro. When you speak a command, the associated macro is activated. The most common is the Keystroke macro, which is what was used to create the commands you've been using up till now. For each command you've spoken, Simon has electronically typed the keystrokes you would normally have typed manually using your keyboard. 

Simon's Objects

The ability to create voice-activated macros is one of Simon's most powerful featuresand it's easy to do. To create macros, you'll being using Simon's built-in objects, which appear in the Vocabulary panel.

 In this chapter, we'll show you how to create macros using Simon's built-in objects. Before we begin, let's take a closer look at some of the Keystroke macros already in Simon's vocabulary. 

A Closer Look at Macros

To view the macros, Simon needs to be in Training mode.

1.	Double-click Simon's icon in the dock. 
The Vocabulary panel opens. 

2.	Click Training. 
Simon stops listening for commands.

3.	Select the Common Words folder in the first level of the browser. 
The commands contained in the Common Words folder appear in the column to the right. 

4.	Select the Close_Window command. 
The Action Inspector appears in the lower half of the Vocabulary panel.

,

The Keyboard macro associated with the Close_Window command (Command-w) is displayed and the Keystroke object appears in the sequencer at the bottom of the panel. If a macro has more than one object, they'll appear in the sequence they're activated (from left to right) in the sequencer. Let's look at another command. 

5.	Select Workspace in the first level of the browser. 
The commands in the Workspace folder appear in the column to the right. 

6.	Select the Browser command. 
The Action Inspector displays the Keyboard macro (Command-Shift-B), and a Keystroke object in the sequencer. 

Note: You cannot create a Keystroke macro for a command that does not have a command key equivalent next to its name in the menu.

Creating Macros

This section describes creating macros using Simon's built-in objects. 

Creating a Keystroke Macro

Use the Keystroke object to create a macro for any command that has a command key appearing next to its name in the menu. In our tutorial, we'll create a Keystroke macro for the menu command Save As. When you speak the command, Simon electronically presses (Command-Shift-S).

To create our tutorial Keystroke macro:

1.	Select the Common Words folder in the first level of the browser. 
The commands in the Common Words folder appear in the column to the right. 

Note: If you're adding an application-specific command, put it in the application's folder. 

2.	Type Save As in the text field beneath the browser, then click Add. 
The Save As command is added to the Common Words folder and appears in italic. 

Notice that the Common Words folder also appears in italic indicating it contains commands that are untrained. Simon cannot listen for commands if there are untrained commands in the Common Words folder. You'll need to train Save As before entering Listening mode.

3.	Click the Keystroke object

,.

The Action Inspector appears in the lower half of the Vocabulary panel, and a Keystroke object is added to the sequencer. 

4.	Click Change Keys¼

The Capture Keys alert panel is displayed prompting you to type the keystrokes associated with this command. 

5.	Type the command key sequence for Save As;press and hold the Shift and Command keys, then type S. When you're finished, click OK.

6.	The keys you pressed appear in the Keyboard Macro window.

7.	Click Train. Train Save_As using the same procedure you learned in Chapter 5.

That's all there is to it! You've created your first voice-activated macro. To create more Keystroke macros, repeat these steps. Remember that you can create a Keystroke macro for any command that has a command key appearing next to the command in its menu. 

Tip: If you want to create several macros at one time, first add all of the commands, then create each macro. When you're finished, train all the commands at oncethis is faster than training each macro right after it's created. 

Creating a Mouse Macro

Use the Mouse object to create animated Mouse macros. In our tutorial, we'll create a Mouse macro to open the Info panel in Workspace

To create our tutorial Mouse macro:

1.	Select Workspace in the first level of the browser. 
The commands in the Workspace folder appear in the column to the right.

Note: Mouse macros are normally tied to a specific application and belong in an application's folder. If you try to add a Mouse macro to the Common Words folder, an alert panel appears to remind you that Mouse macros probably do not belong in the Common Words folder. 

2.	Type a name for your macro in the text field below the browser. For now, type Workspace Info, then click Add. 

3.	Click the Mouse object.

,

The Action Inspector displays instructions on how to create a Mouse macro, and a Mouse object is added to the sequencer. 

4.	Read the instructions, then Click Record. 

NOTE: Before you actually press Esc to begin recording a Mouse macro, you should make the application in which you'll be recording the active application. We'll do that now. 

5.	Double-click the NeXT icon in the dock. 

Workspace is now the active application and its menu appears on screen. You're ready to begin recording.

6.	Press the Esc key ONCE to begin recording. 
The Esc key is located at the top, left of your keyboard. 
DO NOT HOLD THE ESC KEY DOWN WHILE RECORDING. 

You'll hear a system beep when recording begins. The Mouse object is now recording any action you make with your mouse.

7.	Move the mouse to the Workspace menu, then click Info. 

The Info menu appears.

8.	Click Info Panel¼

The Workspace Info panel appears. 

9.	Press the Esc key ONCE to stop recording. 
You'll hear a system beep indicating recording has stopped. 

10.	Click Train. 
Train the new Workspace_Info command. 

You're finished creating a Mouse macro. The next time you use Simon Says, activate Workspace and say ªWorkspace_Info.º Watch as Simon automatically moves the mouse to the Workspace menu, clicks Info, then Info Panel, and the Workspace Info panel appears. 

IMPORTANT: The following limitations apply to Mouse macros. Read them before creating any new Mouse macros. 

·	You cannot drag applications to or from the Workspace dock or move the dock itself. This may result in a Workspace error and cause your computer to automatically log out. 

·	If you create a Mouse macro to grab tools off a palette for example, the palette must always be in the same position on the screen. 

·	For Mouse macros created within a document window (such as Mail), the position of the mouse is relative to the bottom, left corner of the window. If you resize the window, the Mouse macro will not work properly. 

·	Mouse macros are application specific. For example, you cannot add a Mouse macro that clicks Cancel on an Alert panel (no matter which application is active) to the Common Words folder. 

Creating a Sound Macro

Use the Sound object to create a macro that plays a sound file in response to a spoken command. Following are two examples of how you might use a Sound macro:

·	Let's say you're planning a sales presentation (using your NeXT computer and Simon Says, of course!) for a potential client named Bob. Since you know Bob's a patriotic guy, you want to end your presentation by playing the Star Spangled Banner on your NeXT. When you're finished you might say, ªSimon, play Bob's favorite song.º

·	When you start up an application, you might want verbal feedback that the application has been activated.

Both of these Sound macros are easy to create. In our tutorial, we'll create a Sound macro that responds, ªWorkspace has been activatedº each time you activate Workspace with a verbal command. This macro includes two objectsÐa default Application object and a Sound object. 

To create our tutorial Sound macro:

1.	Locate and select the Workspace command in the Common Words folder. 
The word Application appears in the Action Inspector indicating you've selected an application, and Simon's icon appears in the sequencer. 

Simon's icon is the default used for all applications in Simon's vocabulary. 

2.	Click the Sound object. 

,

The Action Inspector displays instructions on how to create a Sound macro. A Sound object is added to the sequencer to the right of the Application object (Simon's icon). 

If a macro is made up of more than one object, the objects are activated as they appear in the sequencer from left to right. In our example, Workspace (the Application object) is launched, followed by the response, ªWorkspace has been activated,º (the Sound object).

3.	Read the instructions, then click Record. 
The Sound object starts recording and a sound icon appears in the sound well.

4.	Say ªWorkspace has been activatedº into your microphone, then click Stop. The Sound object stops recording. 

5.	To listen to the sound you've just recorded, click Play. 

If you'd like to record your sound again, repeat steps 3 and 4. 

The next time you're using Simon Says, say ªWorkspaceº.  Simon activates Workspace and responds, ªWorkspace has been activated.º 

Recording sounds with your microphone is one way to create a Sound object. You can also drag pre-recorded Sound (.snd) files direct from your hard disk into the sound well in the Action Inspector.

Creating a Mail Macro

Use the Mail object to create a macro that automatically addresses a NeXTmail message. In our tutorial, we'll create a Mouse macro to automatically address a NeXTmail message to Metrosoft. 

If you have not yet added the Mail application to Simon's vocabulary, do it now by following the instructions in Chapter 8Adding Applications.

To create our tutorial Mail macro:

1.	Select Mail in the first level of the browser. 
The commands in the Mail folder appear in the column to the right.

2.	Type a name for your macro in the text field below the browser. For now, type Mail to Metrosoft, 
	then click Add.

3.	Click the Mail object.

,

The Action Inspector displays a standard NeXTmail header, and a Mail object is added to the sequencer.

4.	Enter the information that appears in the mail header, then click OK.

5.	Click Train. Train the new Mail to Metrosoft command. 

The next time you use Simon Says, activate Mail and say ªMail to Metrosoft.º Mail is activated (if it's not already running), and a new send window is addressed to Metrosoft. If you'd like and you're connected to the Internet, take a few moments to tell us what you think of Simon Says. 

Creating a Text Macro

Use the Text object to create a macro that pastes text into any application that supports the Paste (command-v) command. In our tutorial, we'll compose a short message that you can use in conjunction with the Mail macro you've just created. 

To create our tutorial Text macro:

1.	Select Mail in the first level of the browser. 
The commands in the Mail folder appear in the column to the right.

2.	Type a name for your macro in the text field below the browser. For now, type Simon's Great, then click Add.

3.	Click the Text object.

,
The Action Inspector displays a text field and ruler. A text object is added to the sequencer. 

4.	Enter the information that appears in the text field, then click OK.

5.	Click Train. Train the new Simon's Great command.
The next time you use Simon Says, activate Mail and say ªMail to Metrosoft.º Mail is activated (if it's not already running), and a new send window is addressed to Metrosoft. Now, click in the message area, then say ªSimon's Great.º The text from our tutorial message is pasted into your mail message. If you'd like, send the message to Metrosoft. 

Creating a UNIX Macro

Use the Unix object to create a macro that internally executes a UNIX command or shell script. In our tutorial, we'll create a UNIX macro to automatically send yourself a mail message indicting the disk space available on your hard disk. 

To create our tutorial UNIX macro:

1.	Select the Common Words folder in the first level of the browser. 
The commands in the Common Words folder appear in the column to the right. 

2.	Type Hard Disk in the text field beneath the browser, then click Add. 
The Hard Disk command is added to the Common Words folder and appears in italic.

3.	Click the UNIX object.

,

The Action Inspector displays a text field for entering a UNIX command and a UNIX object is added to the sequencer. 

4.	Enter in the command;  df mail (your user name), then click OK.
	
Make sure to insert your user namedo not include the parentheses. 

5.	Click Train. Train the new Hard Disk command.
The next time you use Simon Says, say ªHard Disk.º Simon internally executes the UNIX command to check the space available on your hard disk, then sends you a mail message containing the information. 

Creating a Delay Macro

Use the Delay object to create a macro that will pause the execution of the macro for a specified number of seconds then resume, executing the next macro object . In our tutorial, we'll create a Delay macro to pause after playing a sound and then play another sound.   A delay is often desirable when waiting for a panel  to appear before sending text into the panel  with the next part of the macro.

To create our tutorial Delay macro:

1.	Select the Common Words folder in the first level of the browser. 
The commands in the Common Words folder appear in the column to the right. 

2.	Type Delay in the text field beneath the browser, then click Add. 
The Delay command is added to the Common Words folder and appears in italic.

3.	Click on the SND object.  Click the Record button.  Say "Before Delay".  Click the Stop button.
The SND object is added to the macro list.  A sound is recorded in the object.

4.	Click on the Delay object.  

¬

The Action Inspector displays a numeric field for entering a number of seconds for the delay and a Delay object is added to the sequencer. 

5.	Double Click the zero of number of seconds and type 5.  
The Delay object is added to the macro list.  A delay of 5 seconds is set.

6	Click on the SND object. Click the Record button.  Say "After Delay".  Click the Stop button.
	The SND object is added to the macro list.  A sound is recorded in the object.
	
7.	Click Train. Train the new Delay command.
	The next time you use Simon Says, say ªDelayº Simon internally executes the first sound object, waits for the delay time and executes the second sound object. 

Creating an Open File Macro

Use the Open File object to create a macro that will . In our tutorial, we'll create a UNIX macro to automatically send yourself a mail message indicting the disk space available on your hard disk. 

To create our tutorial Open File macro:

1.	Select the Common Words folder in the first level of the browser. 
The commands in the Common Words folder appear in the column to the right. 

2.	Type Open_File in the text field beneath the browser, then click Add. 
The Open_File command is added to the Common Words folder and appears in italic.

3.	Click on the Open File object.  

¬

The Action Inspector displays a well for dropping a file and a Open File object is added to the sequencer. 

4.	Drag this file (09_Chapter_9.rtfd) into the well. 
The Open_File command will open this file when you execute the Open File macro.

5.	Click Train. Train the new Open_File command.
	The next time you use Simon Says, say ªOpen_Fileº Simon internally executes the edit program and open the file in the well.